package cn.wolfcode.web.controller;


import cn.wolfcode.domain.EmployeeNotice;
import cn.wolfcode.service.IEmployeeNoticeService;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.INoticeService;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ModelAttribute;

@Controller
@RequestMapping("/employeeNotice")
public class EmployeeNoticeController {

    @Autowired
    private IEmployeeNoticeService employeeNoticeService;
    @Autowired
    private INoticeService noticeService;


    @RequiredPermission(name="员工_公告_中间表页面",expression="employeeNotice:list")
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        PageInfo<EmployeeNotice> pageInfo = employeeNoticeService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "employeeNotice/list";
    }


    @RequiredPermission(name="员工_公告_中间表删除",expression="employeeNotice:delete")
    @RequestMapping("/delete")
    public String delete(Long id) {
        if (id != null) {
           employeeNoticeService.delete(id);
        }
        return "redirect:/employeeNotice/list";
    }


    @RequestMapping("/updateReadStatus")
    public String updateReadStatus(Long noticeId,Long userId,Model model){
        employeeNoticeService.updateReadStatus(userId,noticeId);
        //查询当前的信息返回到展示页面
        model.addAttribute("notice",noticeService.get(noticeId));
        return "notice/show";
    }


    @RequiredPermission(name="员工_公告_中间表新增/编辑",expression="employeeNotice:input")
    @RequestMapping("/input")
    public String input(Long id, Model model) {
        if (id != null) {
            model.addAttribute("employeeNotice",employeeNoticeService.get(id));
        }
        return "employeeNotice/input";
    }
}
